'use strict';
let models = require("../models/index");

module.exports = function (router) {
    router.get('/', function (req, res) {
        res.send("Here is /user");
    });

    router.get("/create", createUser);

    router.get("/all", findAllUsers);
};

function createUser(req, res) {
    let firstName = req.query.f_name ? req.query.f_name : "Tony",
        lastName = req.query.l_name ? req.query.l_name : "Parker";

    models.User.create({first_name: firstName, last_name: lastName}).then(function (result) {
        res.send(result);
    }).catch(function (err) {
        res.send(err);
    });
}

function findAllUsers(req, res) {
    models.User.findAll().then(function (result) {
        res.send(result);
    }).catch(function (err) {
        res.send(err);
    })
}